package com.industrial.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.system.domain.SysDataReporting;
import com.industrial.system.service.ISysDataReportingService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 数据上报Controller
 *
 * @author SangGuangCan
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/reporting")
public class SysDataReportingController extends BaseController
{
    @Autowired
    private ISysDataReportingService sysDataReportingService;

    /**
     * 查询数据上报列表
     */
    @RequiresPermissions("system:reporting:list")
    @GetMapping("/list")
    public TableDataInfo list(SysDataReporting sysDataReporting)
    {
        startPage();
        List<SysDataReporting> list = sysDataReportingService.selectSysDataReportingList(sysDataReporting);
        return getDataTable(list);
    }

    /**
     * 导出数据上报列表
     */
    @RequiresPermissions("system:reporting:export")
    @Log(title = "数据上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDataReporting sysDataReporting)
    {
        List<SysDataReporting> list = sysDataReportingService.selectSysDataReportingList(sysDataReporting);
        ExcelUtil<SysDataReporting> util = new ExcelUtil<SysDataReporting>(SysDataReporting.class);
        util.exportExcel(response, list, "数据上报数据");
    }

    /**
     * 获取数据上报详细信息
     */
    @RequiresPermissions("system:reporting:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(sysDataReportingService.selectSysDataReportingByBaseId(baseId));
    }

    /**
     * 新增数据上报
     */
    @RequiresPermissions("system:reporting:add")
    @Log(title = "数据上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDataReporting sysDataReporting)
    {
        return toAjax(sysDataReportingService.insertSysDataReporting(sysDataReporting));
    }

    /**
     * 修改数据上报
     */
    @RequiresPermissions("system:reporting:edit")
    @Log(title = "数据上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDataReporting sysDataReporting)
    {
        return toAjax(sysDataReportingService.updateSysDataReporting(sysDataReporting));
    }

    /**
     * 删除数据上报
     */
    @RequiresPermissions("system:reporting:remove")
    @Log(title = "数据上报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(sysDataReportingService.deleteSysDataReportingByBaseIds(baseIds));
    }

    @RequiresPermissions("system:reporting:check")
    @PostMapping("/cityCheckData")
    public AjaxResult cityCheckData(@RequestBody SysDataReporting sysDataReporting){
        return this.sysDataReportingService.cityCheckData(sysDataReporting);
    }
}
